package net.csdn.business.common.domain.common;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.List;

/**
 * @author likun
 * @date 2022/11/3 10:29
 */
@Data
public class ConditionQueryDto implements Serializable {
    public static final String LIKE = "like";

    /**
     * orderBy : desc
     * filters : [{"name":"instanceStatus","values":["RUNNING"]},{"name":"engine","values":["MySQL"]}]
     * pageSize : 10
     * pageNumber : 1
     */

    private Order orderBy;

    private List<Filter> filters;

    private int pageNum = 1;
    private int pageSize = 10;
    /**
     * mybatis-plus searchCount
     */
    private boolean searchCount = true;

    /**
     * 连表查询
     */
    private boolean join;

    @Data
    public static class Filter implements Serializable {
        /**
         * name : instanceStatus
         * values : ["RUNNING"]
         */

        private String name;
        private List<String> values;
        private String operator = StringUtils.EMPTY;

        public Filter(String name, List<String> values) {
            this.name = name;
            this.values = values;
        }

        public Filter(String name, List<String> values, String operator) {
            this.name = name;
            this.values = values;
            this.operator = operator;
        }
    }

    @Data
    public static class Order implements Serializable {
        /**
         * 字段名称
         */
        private String name;
        /**
         * asc desc
         */
        private boolean isAsc;

        public Order(String name, boolean isAsc) {
            this.name = name;
            this.isAsc = isAsc;
        }
    }

    public ConditionQueryDto(List<Filter> filters, int pageSize) {
        this.filters = filters;
        this.pageSize = pageSize;
        this.searchCount = false;
    }

    public ConditionQueryDto(Order orderBy, List<Filter> filters, int pageNum, int pageSize, boolean searchCount, boolean join) {
        this.orderBy = orderBy;
        this.filters = filters;
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.searchCount = searchCount;
        this.join = join;
    }
}